package com.sduty.lucene;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

public class FileRW {
	
	public Map<String, String> load(String path){

		BufferedReader reader = null;
		try {
			InputStream is = this.getClass().getClassLoader().getResourceAsStream(path);
			InputStreamReader isr = new InputStreamReader(is, "UTF-8");
			reader = new BufferedReader(isr);
			String line;
			Map<String, String> data = new HashMap<>();
			while ((line = reader.readLine()) != null) {
				String[] ss = line.split("####");
				if (ss.length < 2) {
					continue;
				}
				data.put("url", ss[0]);
				data.put("title", ss[1]);
			}
			return data;
		} catch (UnsupportedEncodingException | FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	
	}

}
